package com.ruoyi.web.controller.report;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.report.Templet;
import com.ruoyi.system.service.report.ITempletService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报告文字内容模板Controller
 *
 * @author jiadun
 * @date 2021-12-30
 */
@RestController
@RequestMapping("/report/templet")
public class TempletController extends BaseController
{
    @Autowired
    private ITempletService templetService;

    /**
     * 查询报告文字内容模板列表
     */
    @PreAuthorize("@ss.hasPermi('report:templet:list')")
    @GetMapping("/list")
    public TableDataInfo list(Templet templet)
    {
        startPage();
        List<Templet> list = templetService.selectTempletList(templet);
        return getDataTable(list);
    }

    /**
     * 导出报告文字内容模板列表
     */
    @PreAuthorize("@ss.hasPermi('report:templet:export')")
    @Log(title = "报告文字内容模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Templet templet)
    {
        List<Templet> list = templetService.selectTempletList(templet);
        ExcelUtil<Templet> util = new ExcelUtil<Templet>(Templet.class);
        util.exportExcel(response, list, "报告文字内容模板数据");
    }

    /**
     * 获取报告文字内容模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('report:templet:query')")
    @GetMapping(value = "/{temid}")
    public AjaxResult getInfo(@PathVariable("temid") Long temid)
    {
        return AjaxResult.success(templetService.selectTempletByTemid(temid));
    }

    /**
     * 新增报告文字内容模板
     */
    @PreAuthorize("@ss.hasPermi('report:templet:add')")
    @Log(title = "报告文字内容模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Templet templet)
    {
        return toAjax(templetService.insertTemplet(templet));
    }

    /**
     * 修改报告文字内容模板
     */
    @PreAuthorize("@ss.hasPermi('report:templet:edit')")
    @Log(title = "报告文字内容模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Templet templet)
    {
        return toAjax(templetService.updateTemplet(templet));
    }

    /**
     * 删除报告文字内容模板
     */
    @PreAuthorize("@ss.hasPermi('report:templet:remove')")
    @Log(title = "报告文字内容模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{temids}")
    public AjaxResult remove(@PathVariable Long[] temids)
    {
        return toAjax(templetService.deleteTempletByTemids(temids));
    }
}
